package com.xjtu.controller.admin;


import com.xjtu.dto.serviceRecord.AddServiceRecordDto;
import com.xjtu.dto.serviceRecord.UpdateServiceDto;
import com.xjtu.result.PageResult;
import com.xjtu.result.Result;
import com.xjtu.service.ServiceRecordService;
import com.xjtu.vo.serviceRecord.ServiceRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/service")
@Slf4j
@Api(tags = "管理员端服务管理接口")
public class ServiceController {
    @Autowired
    private ServiceRecordService serviceRecordService;

    @PostMapping
    @ApiOperation("新增服务记录")
    public Result<ServiceRecordVo> save(@RequestBody @Valid AddServiceRecordDto addServiceRecordDto) {
        ServiceRecordVo resp = serviceRecordService.save(addServiceRecordDto);
        return Result.success(resp);
    }

    @PutMapping
    @ApiOperation("修改服务记录")
     public Result<ServiceRecordVo> update(@RequestBody @Valid UpdateServiceDto updateServiceRecordDto){
        ServiceRecordVo resp = serviceRecordService.update(updateServiceRecordDto);
        return Result.success(resp);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id获取服务的记录")
    public Result<ServiceRecordVo> queryById(@PathVariable @NotNull @Min(value = 1,message = "参数根式错误") Integer id){
        ServiceRecordVo resp = serviceRecordService.queryById(id);
        return Result.success(resp);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询用户信息")
    public Result<PageResult> getMedicalVisitList(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(required = false, defaultValue = "10")Integer size,
                                                  @RequestParam(required = false, defaultValue = "null") String name){
        PageResult resp = serviceRecordService.pageQuery(page,size,name);
        return Result.success(resp);
    }
}
